#include <stdio.h>
#include "crc16.h"

int main() {
    unsigned char data[9] = "123456789";

    CRC16_16 crc16_16;
    crc16_16.crcPoly = 0x8005;
    crc16_16.crcInit = 0xffff;
    crc16_16.crcXor = 0x0000;
    crc16_16.crcRefIn = 1;
    crc16_16.crcRefOut = 1;

    CRC16_256 crc16_256;
    crc16_256.crcPoly = 0x8005;
    crc16_256.crcInit = 0xffff;
    crc16_256.crcXor = 0x0000;
    crc16_256.crcRefIn = 1;
    crc16_256.crcRefOut = 1;

    unsigned short crc16;
    unsigned short i;

    create_crc16_table16(&crc16_16);
    crc16 = generate_crc16(&crc16_16, 16, data, 9);
    printf("0x%04x\n", crc16);

    printf("----------\n");

    create_crc16_table256(&crc16_256);
    crc16 = generate_crc16(&crc16_256, 256, data, 9);
    printf("0x%04x\n", crc16);

    printf("----------\n");

    prepare_crc16_with_table16(&crc16_16, &crc16);
    for(i = 0; i < 9; i++) {
        process_crc16_with_table16(&crc16_16, &data[i], &crc16);
    }
    complete_crc16_with_table16(&crc16_16, &crc16);
    printf("0x%04x\n", crc16);

    printf("----------\n");

    prepare_crc16_with_table256(&crc16_256, &crc16);
    for(i = 0; i < 9; i++) {
        process_crc16_with_table256(&crc16_256, &data[i], &crc16);
    }
    complete_crc16_with_table256(&crc16_256, &crc16);
    printf("0x%04x\n", crc16);

    return 0;
}
